package likong.bibliothek.pages.buch;

import likong.bibliothek.obj.Buch;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.model.IModel;

import db.HibernateHelper;

public class BuecherEdit extends BuchAbstract{
	public BuecherEdit(final PageParameters params) {
			// Load Person
			Buch buch = HibernateHelper.retrieveObject(Buch.class, params.getInt("buchID")); 

			if (buch == null) {
				// Fehler: Zurück zur Übersicht
				setRedirect(true);
				setResponsePage(BuecherWeb.class);
				return;
			}
			
			final CompoundPropertyModel<Buch> model = new CompoundPropertyModel<Buch>(buch);
			
			// Panel einfügen
			add(new BuecherFormPanel("editBuchFormular", model) {
				private static final long serialVersionUID = 1L;

				@Override
				protected void onSubmitModelHandle(IModel<Buch> model) {
					HibernateHelper.saveOrUpdate(model.getObject());
					
					this.setRedirect(true);
					this.setResponsePage(BuecherWeb.class, params);
				}
			});
			
		}
	}

